// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { ListViewAdapter } from "../../../../script/util/ListView/ListViewAdapter";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    @property(ListViewAdapter)
    list: ListViewAdapter = null;

    start () {
        //获取所有公司的产业
        this.getData();
        this.registerEvent("upCompany", () => {this.getData()});
    }
    getData() {
        let data = game.playerMgr.heroInfo.companyList as any;
        
        data.sort((a, b) => {
            // return a.isLock - b.isLock;
           return this.sortFn(a.id, b.id);
        })
        this.list.updateItems(data);
    }
    sortFn(aId, bId) {
        let a = game.playerMgr.bag.companyBag.getItem(aId);
        let b = game.playerMgr.bag.companyBag.getItem(bId);
        if( a && b) {
            return 0;
        }else if( a && !b) {
            return -1;
        }else if(!a && b){
            return 1;
        }else if(!a && !b) {
            return 0;
        }
    }
    // update (dt) {}
}
